﻿#ifndef __SS_MYSQL_POOL_H__
#define __SS_MYSQL_POOL_H__
#include "../ssMySQLStmtQuery.h"
#include "thread/threadLock/ssThreadLockGuard.h"
#include <list>
#include <vector>

namespace StarSeeker
{

class ssMySQLPool
{
public:
	ssMySQLPool();
	virtual ~ssMySQLPool();
	//初始化连接
	void Init(const char *pIP, u32	port, const char *pAccount, const char *pPW, const char *pDBName, u32 count=10);
	//等待结束，必须等到所有连接都归还后才会结束
	void WaitForExit();
	//设置字符集，会调用所有连接查询数据库，多线程环境请注意
	void SetCharacter(const char *pc);
	//设置数据库，会调用所有连接查询数据库，多线程环境请注意
	void SelectDB(const char *pDBName);
	//获取连接
	ssMySQLStmtQuery* GetConnection();
	//归还连接
	void ReleaseConnection(ssMySQLStmtQuery* pConn);
	//清理内存
	void ClearAllBuffer();
	//增加预处理
	bool AddPrepare(u32 id, const char* pIn, const char* pOut, const char* pSql, const u8 resultFlag);
protected:
	std::list<ssMySQLStmtQuery*>	m_free;
	std::vector<ssMySQLStmtQuery*>	m_all;
	ssThreadLock					m_lock;
};

}
#endif
